package com.ljkj.blockpay.network;

import com.ljkj.blockpay.basedata.BuildConfig;
import com.ljkj.blockpay.model.CommonModel;
import com.ljkj.blockpay.model.RechargeModel;
import com.ljkj.blockpay.model.UserModel;
import com.ljkj.blockpay.network.response.BaseListResponse;
import com.ljkj.blockpay.network.response.BaseResponse;
import com.ljkj.blockpay.util.SaveModelToSPUtil;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import io.reactivex.Flowable;
import io.reactivex.Single;

/**
 * Created by yp on 2022/3/10
 */
public class MainRepository {

    private ApiService apiService;

    private static class SingletonHelper {
        private static final MainRepository INSTANCE = new MainRepository();
    }

    public static MainRepository getInstance() {
        return SingletonHelper.INSTANCE;
    }

    private MainRepository() {
        apiService = ApiServiceFactory.createApiServiceImpl(ApiService.class);
    }

    //获取国家地区代码
    public Single<BaseResponse<List<CommonModel>>> getValidateCode(){
        return apiService.getValidateCode();
    }

    //获取验证码
    public Single<BaseResponse<UserModel>> getCode(String countryCode, String email, String mobile, String tempCode){
        Map<String, Object> params = new HashMap<>();
        params.put("countryCode", countryCode);
        params.put("email", email);
        params.put("mobile", mobile);
        params.put("tempCode", tempCode);
        return apiService.getCode(params);
    }

    //用户注册
    public Flowable<BaseResponse<String>> userRegister(String code, String countryCode, String email, String mobile, String password, String userType){
        Map<String, Object> params = new HashMap<>();
        params.put("code", code);
        params.put("countryCode", countryCode);
        params.put("email",email);
        params.put("mobile",mobile);
        params.put("password",password);
        params.put("userType",userType);
        return apiService.userRegister(params);
    }

    //用户登录
    public Single<BaseResponse<UserModel>> userLogin(String code, String countryCode, String email, String mobile, String password){
        Map<String, Object> params = new HashMap<>();
        params.put("code", code);
        params.put("countryCode", countryCode);
        params.put("email",email);
        params.put("mobile",mobile);
        params.put("password",password);
        return apiService.userLogin(params);
    }

    //业务场景支持币种and网络精度
    //(query)订单类型(1=充值,2=转账,3=提币,4=兑换,5=扫码付)
    public Single<BaseListResponse<RechargeModel>> getNetAccuracy() {
        return apiService.getNetAccuracy("1");
    }


}
